// StaffButton.java
// Created by Robert Lee
// 12/5/12
// StaffButton is the individual Button for each note on the Staff

package urnoted;
import java.awt.*;
import java.awt.event.*;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.*;

import urnoted.Controller;

public class StaffButton extends JButton {
    private static final int WIDTH = 240;
    private static final int HEIGHT = 15;  // dictated by StaffPanel's drawStaff()
    private static final Dimension DIMENSION = new Dimension(WIDTH, HEIGHT);
    private static final Border BORDER = new LineBorder(Color.BLACK, 1);
    private Controller controller;
    private int index;    //  index in the StaffPanel's staffbutton list
    private String name;  // e.g., "E4"
    
    public StaffButton(final Controller controller, int index, String name) {
        this.controller = controller;
        this.index = index;
        this.name = name;
        this.addActionListener(new ActionListener(){  // anonymous inner class
            @Override
            public void actionPerformed(ActionEvent event) {
                setCurrentStaffButton();
                // play current note?
            }
        });
        this.setPreferredSize(DIMENSION);
        //this.setBorder(BORDER);
        //this.setBackground(Color.WHITE);
        this.setOpaque(false);
        this.setContentAreaFilled(false);
        this.setBorder(BorderFactory.createEmptyBorder());
    }

    /*@Override
    protected void paintComponent(Graphics g) {  // draw black keys
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        
        // Draw line if it is C4 etc here????
        
        char ch = name.charAt(0);  // e.g., 'B'
        if (ch == 'B' || ch == 'E') {
            g.fillRect(0, 0, BW2, BH);
        } else if (ch == 'C' || ch == 'F') {
            g.fillRect(BO, 0, BW2, BH);
        } else {
            g.fillRect(0, 0, BW2, BH);
            g.fillRect(BO, 0, BW2, BH);
        } 
        
        // Draw name... dont need to do this for the staff note???
        String label = name.substring(0, 1);
        g.setFont(new Font("Arial Bold", Font.BOLD, 40));
        g.drawString(label, 11, HEIGHT+8);
    }*/

    public int getIndex() {
        return index;
    }

    public String getName() {
        return name;
    }

    private void setCurrentStaffButton() {
        controller.setCurrentStaffButton(this);
    }
}
